package com.shop2cn.iapi.member.testcase;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.shop2cn.iapi.member.parameter.MchSetOpenPointsRuleBean;
import com.shop2cn.iapi.member.parameter.PointsRuleDto;
import com.shop2cn.iapi.member.service.MchSetOpenPointsRuleCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.shenqi.GodmchManageCallService;
import com.ymttest.database.model.godmember.PointsRule;
import com.ymttest.database.sqlwapper.godmember.GodMemberWapper;
/**
*商家设置积分功能
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_MchSetOpenPointsRule{
	private static MchSetOpenPointsRuleBean MchSetOpenPointsRuleBean;
	private static MchSetOpenPointsRuleCall MchSetOpenPointsRuleCall;
	private static Integer shopid ;
	GodMemberWapper GodMemberWapper;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("商家设置积分规则功能");
		try {
			shopid= GodmchManageCallService.CreateSellerMch();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	@Before
	public void caseUp() {
		MchSetOpenPointsRuleBean=new MchSetOpenPointsRuleBean();
		MchSetOpenPointsRuleCall=new MchSetOpenPointsRuleCall();
		GodMemberWapper=new GodMemberWapper();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(MchSetOpenPointsRuleCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_MchSetOpenPointsRule_001() {
		Logger.start(true,"商家设置积分功能成功");
		try {
			//MchSetOpenPointsRuleBean.setOpenPoints(true);
			MchSetOpenPointsRuleBean.setShopId(shopid);
			List<PointsRuleDto> pointsRuleList=new ArrayList<PointsRuleDto>();
			//100000 - 下单送积分，110000 - 取消订单扣积分
			//200000 - 商家送积分，210000 - 商家扣积分
			PointsRuleDto prd=new PointsRuleDto();
			prd.setBizType(100000);
			prd.setPoints(1);
			prd.setThreshold("100");
			pointsRuleList.add(prd);
			
			PointsRuleDto prd2=new PointsRuleDto();
			prd2.setBizType(110000);
			prd2.setPoints(1);
			prd2.setThreshold("100");
			pointsRuleList.add(prd2);
			
			PointsRuleDto prd3=new PointsRuleDto();
			prd3.setBizType(200000);
			prd3.setPoints(2);
			prd3.setThreshold("100");
			pointsRuleList.add(prd3);
			
			PointsRuleDto prd4=new PointsRuleDto();
			prd4.setBizType(210000);
			prd4.setPoints(2);
			prd4.setThreshold("100");
			pointsRuleList.add(prd4);
			
			MchSetOpenPointsRuleBean.setPointsRuleList(pointsRuleList);
			MchSetOpenPointsRuleCall.setData(MchSetOpenPointsRuleBean);
			MchSetOpenPointsRuleCall.callService();			
			Logger.verifyEquals("200", MchSetOpenPointsRuleCall.getString("code"), "验证code");
			List<PointsRule> dblist = GodMemberWapper.selectPointsRuleByShopId(shopid);
			dblist.forEach(x->{
				pointsRuleList.forEach(y->{
					if(y.getBizType().equals(x.getBizType())) {
						Logger.verifyEquals(y.getPoints(), x.getPoints(), "验证getPoints");
						Logger.verifyEquals(new BigDecimal( y.getThreshold()).setScale(2), x.getThreshold().setScale(2), "验证getThreshold");
					}
				});
			});
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_MchSetOpenPointsRule_002() {
		Logger.start(true,"不输入shopid失败");
		try {
			//MchSetOpenPointsRuleBean.setOpenPoints(true);
//			MchSetOpenPointsRuleBean.setShopId(shopid);
//			List<PointsRuleDto> pointsRuleList=new ArrayList<PointsRuleDto>();
			//100000 - 下单送积分，110000 - 取消订单扣积分
			//200000 - 商家送积分，210000 - 商家扣积分
//			PointsRuleDto prd=new PointsRuleDto();
//			prd.setBizType(100000);
//			prd.setPoints(1);
//			prd.setThreshold("100");
//			pointsRuleList.add(prd);
//			
//			PointsRuleDto prd2=new PointsRuleDto();
//			prd2.setBizType(110000);
//			prd2.setPoints(1);
//			prd2.setThreshold("100");
//			pointsRuleList.add(prd2);
//			
//			PointsRuleDto prd3=new PointsRuleDto();
//			prd3.setBizType(200000);
//			prd3.setPoints(2);
//			prd3.setThreshold("100");
//			pointsRuleList.add(prd3);
//			
//			PointsRuleDto prd4=new PointsRuleDto();
//			prd4.setBizType(210000);
//			prd4.setPoints(2);
//			prd4.setThreshold("100");
//			pointsRuleList.add(prd4);
//			
//			MchSetOpenPointsRuleBean.setPointsRuleList(pointsRuleList);
			MchSetOpenPointsRuleCall.setData(MchSetOpenPointsRuleBean);
			MchSetOpenPointsRuleCall.callService();			
			Logger.verifyEquals("400", MchSetOpenPointsRuleCall.getString("code"), "验证code");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	@Ignore
	//接口拆开
	public void Tc_MchSetOpenPointsRule_003() {
		Logger.start(true,"不输入openPoints失败");
		try {
//			//MchSetOpenPointsRuleBean.setOpenPoints(true);
			MchSetOpenPointsRuleBean.setShopId(shopid);
			List<PointsRuleDto> pointsRuleList=new ArrayList<PointsRuleDto>();
			//100000 - 下单送积分，110000 - 取消订单扣积分
			//200000 - 商家送积分，210000 - 商家扣积分
			PointsRuleDto prd=new PointsRuleDto();
			prd.setBizType(100000);
			prd.setPoints(1);
			prd.setThreshold("100");
			pointsRuleList.add(prd);
			
			PointsRuleDto prd2=new PointsRuleDto();
			prd2.setBizType(110000);
			prd2.setPoints(1);
			prd2.setThreshold("100");
			pointsRuleList.add(prd2);
			
			PointsRuleDto prd3=new PointsRuleDto();
			prd3.setBizType(200000);
			prd3.setPoints(2);
			prd3.setThreshold("100");
			pointsRuleList.add(prd3);
			
			PointsRuleDto prd4=new PointsRuleDto();
			prd4.setBizType(210000);
			prd4.setPoints(2);
			prd4.setThreshold("100");
			pointsRuleList.add(prd4);
			
//			MchSetOpenPointsRuleBean.setPointsRuleList(pointsRuleList);
			MchSetOpenPointsRuleCall.setData(MchSetOpenPointsRuleBean);
			MchSetOpenPointsRuleCall.callService();			
			Logger.verifyEquals("400", MchSetOpenPointsRuleCall.getString("code"), "验证code");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	@Ignore
	//接口拆开
	public void Tc_MchSetOpenPointsRule_004() {
		Logger.start(true,"openPoints为true时不输入pointsRuleList失败");
		try {
			//MchSetOpenPointsRuleBean.setOpenPoints(true);
			MchSetOpenPointsRuleBean.setShopId(shopid);
			List<PointsRuleDto> pointsRuleList=new ArrayList<PointsRuleDto>();
			//100000 - 下单送积分，110000 - 取消订单扣积分
			//200000 - 商家送积分，210000 - 商家扣积分
			PointsRuleDto prd=new PointsRuleDto();
			prd.setBizType(100000);
			prd.setPoints(1);
			prd.setThreshold("100");
			pointsRuleList.add(prd);
			
			PointsRuleDto prd2=new PointsRuleDto();
			prd2.setBizType(110000);
			prd2.setPoints(1);
			prd2.setThreshold("100");
			pointsRuleList.add(prd2);
			
			PointsRuleDto prd3=new PointsRuleDto();
			prd3.setBizType(200000);
			prd3.setPoints(2);
			prd3.setThreshold("100");
			pointsRuleList.add(prd3);
			
			PointsRuleDto prd4=new PointsRuleDto();
			prd4.setBizType(210000);
			prd4.setPoints(2);
			prd4.setThreshold("100");
			pointsRuleList.add(prd4);
			
//			MchSetOpenPointsRuleBean.setPointsRuleList(pointsRuleList);
			MchSetOpenPointsRuleCall.setData(MchSetOpenPointsRuleBean);
			MchSetOpenPointsRuleCall.callService();			
			Logger.verifyEquals("400", MchSetOpenPointsRuleCall.getString("code"), "验证code");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	@Ignore
	//这一期不判断
	public void Tc_MchSetOpenPointsRule_006() {
		Logger.start(true,"pointsRuleList中的biztype不在config中失败");
		try {
			org.junit.Assert.fail();
			MchSetOpenPointsRuleCall.setData(MchSetOpenPointsRuleBean);
			MchSetOpenPointsRuleCall.callService();			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}